package dhbw.GUI.Menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import dhbw.Data.Language;
import dhbw.Data.Settings;
import Main.MyController;

public class MenuDatei extends JMenu implements ActionListener{

	private JMenuItem beendenItem;
	private JMenuItem saveItem;
	private JMenuItem logoutItem;
	private MyController myc;
	private boolean speichern;
	
	public MenuDatei(MyController myc, boolean speichern)
	{
		this.myc = myc;
		this.speichern=speichern;
		buildMenu();
	}

	/**
	 * build JMenu Datei
	 */
	private void buildMenu()
	{
		saveItem = new JMenuItem(Language.SAVE[myc.getLanguage()]);
		saveItem.addActionListener(this);
		saveItem.setIcon(Settings.SAVE_ICON);
		logoutItem = new JMenuItem(Language.LOGOUT[myc.getLanguage()]);
		logoutItem.addActionListener(this);
		logoutItem.setIcon(Settings.LOGOUT_ICON);
		if(speichern)
			this.add(saveItem);
		beendenItem = new JMenuItem(Language.EXIT[myc.getLanguage()]);
		this.setText(Language.FILE[myc.getLanguage()]);
		beendenItem.addActionListener(this);
		beendenItem.setIcon(Settings.EXIT_ICON);
		this.add(logoutItem);
		this.add(beendenItem);
	}
	
	@Override
	/**
	 * Click-Listener for JMenu
	 */
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource().equals(beendenItem))
		{
			this.myc.exit();
		}
		if(arg0.getSource().equals(logoutItem))
			this.myc.logout();
		if(arg0.getSource().equals(saveItem))
			this.myc.saveAll();
	}
}
